The data set contains information about three species of IRIS flowers namely:
Four features are collected from each sample, sepal-length, sepal-width, petal-length and petal-width in centi-meters.
# Common imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
iris_df = pd.read_csv("./data/IRIS.csv.gz", compression="gzip")
iris_df.sample(5)
fig = px.scatter_3d(iris_df, x='sepal_length', y='sepal_width', z='petal_width',
color='species', template="plotly_dark")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
covid_df = pd.read_csv("./data/owid-covid-data.csv.gz", compression="gzip")
covid_df.sample(5)
required_columns = ["iso_code", "location", "continent", "date", "new_cases_smoothed", "total_cases"]
covid_df = covid_df.dropna(subset = required_columns)
covid_df = covid_df.sort_values("date")
covid_df[['iso_code', 'location']].sample(8)
covid_day_df = covid_df[covid_df.date == "2021-12-23"]
covid_day_df.sample(5)
fig = px.scatter_geo(covid_day_df, locations="iso_code", color="continent",
hover_name="location", size="new_cases_smoothed",
projection="natural earth", template="plotly_dark")
fig.show()
fig = px.scatter_geo(covid_df, locations="iso_code", color="continent",
hover_name="location", size="total_cases",
projection="natural earth", animation_frame="date", template="plotly_dark")
fig.show()
import torchvision
import os
import matplotlib.pyplot as plt
from matplotlib import rc
from matplotlib.animation import FuncAnimation
from matplotlib import animation
rc('animation', html='jshtml')
frn = 10 # Number of frames to process in the animation
fps = 0.5 # Frames per second
mywriter = animation.PillowWriter(fps=fps)
mnist_dataset = torchvision.datasets.MNIST(root = "data/mnist", train = True, download = True, transform=torchvision.transforms.ToTensor())
fig, ax = plt.subplots(figsize = (10, 10))
def change_plot(frame_idx):
ax.cla()
image_tensor = mnist_dataset[frame_idx][0]
image_tensor_gray = image_tensor[0]
image_tensor_gray = image_tensor_gray * 255
ax.matshow(image_tensor_gray, cmap = "gray")
for i in range(image_tensor_gray.shape[0]):
for j in range(image_tensor_gray.shape[1]):
ax.text(i, j, str(int(image_tensor_gray[j][i].item())), va = "center", ha = "center", color = "blue", fontsize = "small")
ax.axis("off")
plt.tight_layout()
anim = FuncAnimation(fig, change_plot, frn, interval=1000 / fps)
plt.close()
anim
mywriter = animation.PillowWriter(fps=fps)
if not os.path.exists("./assets/gif"):
os.makedir("./assets/gif")
anim.save('./assets/gif/mnist.gif',writer=mywriter)